# -*- coding: utf-8 -*-
# __author__:heliujiang
# 20222/4/3 09:57

import requests
from common.test_log import create_logger

# 获取token
class GetToken:
    _instance = None
    logger = create_logger()
    def __new__(cls, *args, **kwargs):
        if cls._instance is None:
            cls._instance = super().__new__(cls)
        return cls._instance


    def get_token(self, test_data,host):
        if host == 'dev':
            self.host = 'https://tspdev.dfmc.com.cn:486/buz-user-service/app/getToken'
        elif host == 'uat':
            self.host = 'https://vpretspcloud.dfmc.com.cn/buz-user-service/app/getToken'
        elif host == 'pro':
            self.host = 'https://vtspcloud.dfmc.com.cn/buz-user-service/app/getToken'
        url = self.host
        res = requests.request(method='POST', json=test_data, url=url)
        return res.json()["model"]['token']
